package it.com.Test.a4_either;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class TestOfAcceptEither {
    static ExecutorService executor = Executors.newFixedThreadPool(3);

    public static void main(String[] args) {
        System.out.println("main....start....");
        CompletableFuture<Integer> task1 = CompletableFuture.supplyAsync(() -> {
            System.out.println("任务一开始");
            System.out.println("任务一结束***");
            return 10;
        }, executor);
        CompletableFuture<Integer> task2 = CompletableFuture.supplyAsync(() -> {
            System.out.println("任务二开始");
            try {Thread.sleep(3000);} catch (InterruptedException e) {e.printStackTrace();}
            System.out.println("任务二结束***");
            return 20;
        }, executor);

        task1.acceptEitherAsync(task2, (r1) -> {
            System.out.println("任务三开始");
            System.out.println("获取完成任务的结果：" + r1);
            System.out.println("任务三结束***");
        }, executor);
        System.out.println("main....end....");
    }
    /**
     main....start....
     任务一开始
     任务一结束***
     任务二开始
     main....end....
     任务三开始
     获取完成任务的结果：10
     任务三结束***
     任务二结束***

     */
}
